<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for javascripts/explorev2/stores/store.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../../prettify.css" />
    <link rel="stylesheet" href="../../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../../index.html">All files</a> / <a href="index.html">javascripts/explorev2/stores</a> store.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">17.19% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>11/64</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/42</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">20% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>3/15</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">18.33% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>11/60</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">234x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">117x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">/* eslint camelcase: 0 */
import controls from './controls';
import visTypes, { sectionsToRender } from './visTypes';
&nbsp;
export function getFormDataFromControls(controlsState) {
  const formData = {};
  Object.keys(controlsState).forEach(controlName =&gt; {
    formData[controlName] = controlsState[controlName].value;
  });
  return formData;
}
&nbsp;
export f</span>unction <span class="fstat-no" title="function not covered" >getControlNames(vizType, datasourceType) {
  c</span>onst controlNames = <span class="cstat-no" title="statement not covered" >[];
<span class="cstat-no" title="statement not covered" >  sectionsToRender(vizType, datasourceType).forEach(</span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    section =&gt; section.controlSetRows.forEach(</span></span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >      fsr =&gt; fsr.forEach(</span></span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >        f =&gt; controlNames.push(f))));</span></span>
<span class="cstat-no" title="statement not covered" >  return controlNames;</span>
}
&nbsp;
export f</span>unction <span class="fstat-no" title="function not covered" >getControlsState(state, form_data) {
  /*
  * Gets a new controls object to put in the state. The controls object
  * is similar to the configuration control with only the controls
  * related to the current viz_type, materializes mapStateToProps functions,
  * adds value keys coming from form_data passed here. This can't be an action creator
  * just yet because it's used in both the explore and dashboard views.
  * */
&nbsp;
  // Getting a list of active control names for the current viz
  c</span>onst formData = <span class="cstat-no" title="statement not covered" >Object.assign({}, form_data);
  c</span>onst vizType = <span class="cstat-no" title="statement not covered" >formData.viz_type || 'table';
&nbsp;
  c</span>onst controlNames = <span class="cstat-no" title="statement not covered" >getControlNames(vizType, state.datasource.type);
&nbsp;
  c</span>onst viz = <span class="cstat-no" title="statement not covered" >visTypes[vizType];
  c</span>onst controlOverrides = <span class="cstat-no" title="statement not covered" >viz.controlOverrides || {};
  c</span>onst controlsState = <span class="cstat-no" title="statement not covered" >{};
<span class="cstat-no" title="statement not covered" >  controlNames.forEach(<span class="fstat-no" title="function not covered" >(</span>k) =&gt; {</span>
    c</span>onst control = <span class="cstat-no" title="statement not covered" >Object.assign({}, controls[k], controlOverrides[k]);
<span class="cstat-no" title="statement not covered" >    if (control.mapStateToProps) {</span>
<span class="cstat-no" title="statement not covered" >      Object.assign(control, control.mapStateToProps(state));</span>
<span class="cstat-no" title="statement not covered" >      delete control.mapStateToProps;</span>
    }
&nbsp;
    // If the value is not valid anymore based on choices, clear it
<span class="cstat-no" title="statement not covered" >    if (control.type === 'SelectControl' &amp;&amp; control.choices &amp;&amp; k !== 'datasource' &amp;&amp; formData[k]) {</span>
      c</span>onst choiceValues = <span class="cstat-no" title="statement not covered" >control.choices.map(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >c =&gt; c[0]);</span></span>
<span class="cstat-no" title="statement not covered" >      if (control.multi &amp;&amp; formData[k].length &gt; 0 &amp;&amp; choiceValues.indexOf(formData[k][0]) &lt; 0) {</span>
<span class="cstat-no" title="statement not covered" >        delete formData[k];</span>
      } else <span class="cstat-no" title="statement not covered" >if (!control.multi &amp;&amp; !control.freeForm &amp;&amp; choiceValues.indexOf(formData[k]) &lt; 0) {</span>
<span class="cstat-no" title="statement not covered" >        delete formData[k];</span>
      }
    }
    // Removing invalid filters that point to a now inexisting column
<span class="cstat-no" title="statement not covered" >    if (control.type === 'FilterControl' &amp;&amp; control.choices) <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >{</span></span></span>
<span class="cstat-no" title="statement not covered" >      if (!formData[k]) {</span>
<span class="cstat-no" title="statement not covered" >        formData[k] = [];</span>
      }
      c</span>onst choiceValues = <span class="cstat-no" title="statement not covered" >control.choices.map(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >c =&gt; c[0]);</span></span>
<span class="cstat-no" title="statement not covered" >      formData[k] = formData[k].filter(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >flt =&gt; choiceValues.indexOf(flt.col) &gt;= 0);</span></span></span>
    }
&nbsp;
<span class="cstat-no" title="statement not covered" >    if (typeof control.default === 'function') {</span>
<span class="cstat-no" title="statement not covered" >      control.default = control.default(control);</span>
    }
<span class="cstat-no" title="statement not covered" >    control.value = formData[k] !== undefined ? formData[k] : control.default;</span>
<span class="cstat-no" title="statement not covered" >    controlsState[k] = control;</span>
  });
<span class="cstat-no" title="statement not covered" >  return controlsState;</span>
}
&nbsp;
export f</span>unction <span class="fstat-no" title="function not covered" >applyDefaultFormData(form_data) {
  c</span>onst datasourceType = <span class="cstat-no" title="statement not covered" >form_data.datasource.split('__')[1];
  c</span>onst vizType = <span class="cstat-no" title="statement not covered" >form_data.viz_type || 'table';
  c</span>onst viz = <span class="cstat-no" title="statement not covered" >visTypes[vizType];
  c</span>onst controlNames = <span class="cstat-no" title="statement not covered" >getControlNames(vizType, datasourceType);
  c</span>onst controlOverrides = <span class="cstat-no" title="statement not covered" >viz.controlOverrides || {};
  c</span>onst formData = <span class="cstat-no" title="statement not covered" >{};
<span class="cstat-no" title="statement not covered" >  controlNames.forEach(<span class="fstat-no" title="function not covered" >k =&gt; </span>{</span>
    c</span>onst control = <span class="cstat-no" title="statement not covered" >Object.assign({}, controls[k]);
<span class="cstat-no" title="statement not covered" >    if (controlOverrides[k]) {</span>
<span class="cstat-no" title="statement not covered" >      Object.assign(control, controlOverrides[k]);</span>
    }
<span class="cstat-no" title="statement not covered" >    if (form_data[k] === undefined) {</span>
<span class="cstat-no" title="statement not covered" >      if (typeof control.default === 'function') {</span>
<span class="cstat-no" title="statement not covered" >        formData[k] = control.default(controls[k]);</span>
      } else {
<span class="cstat-no" title="statement not covered" >        formData[k] = control.default;</span>
      }
    } else {
<span class="cstat-no" title="statement not covered" >      formData[k] = form_data[k];</span>
    }
  });
<span class="cstat-no" title="statement not covered" >  return formData;</span>
}
&nbsp;
export const autoQueryControls = [
  'datasource',
  'viz_type',
];
&nbsp;
const defaultControls = Object.assign({}, controls);
Object.keys(controls).forEach((f) =&gt; {
  defaultControls[f].value = controls[f].default;
});
&nbsp;
const defaultState = {
  controls: defaultControls,
  form_data: getFormDataFromControls(defaultControls),
};
&nbsp;
export { defaultControls, defaultState };
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Apr 11 2017 20:15:55 GMT-0700 (PDT)
</div>
</div>
<script src="../../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../../sorter.js"></script>
</body>
</html>
